<?php


namespace app\user\controller;


use app\common\Check;
use think\Db;
use think\facade\Request;

class ErrorReport extends LoggingBase
{
    /**
     * 界面：错误报告
     */
    public function Index(){
        $Css = array(
            '<link href="/layui/css/layui.css" rel="stylesheet"/>'
        );
        return $this->mb_Display('错误报告', 'ErrorReport', 'index', $Css);
    }

    /**
     * 接口，提交错误报告
     */
    public function mb_Submit()
    {
        $Email = Request::has('Email') ? Request::param('Email') : '';
        $Content = Request::has('Content') ? Request::param('Content') : '';
        $ImageUrls = Request::has('ImageUrls') ? Request::param('ImageUrls') : '';

        if (!$Email) mb_OutMessage(ErrCode_Toast, '请输入电子邮箱');
        if (!$Content) mb_OutMessage(ErrCode_Toast, '请输入报告内容');
        if (!Check::IsEmail($Email)) mb_OutMessage(ErrCode_Toast, '请输入合法格式的电子邮箱');

        Db::startTrans();
        try {
            $Data = array(
                'UserID'=>$this->m_User->ID,
                'Email'=>$Email,
                'Content'=>$Content,
                'ImageUrls'=>$ImageUrls
            );
            Db::table('error_report')->insert($Data);
            Db::commit();
        } catch (\Exception $e) {
            Db::rollback();
        }
        mb_OutMessage(ErrCode_Normal,'感谢您的反馈，收到后我们会尽快处理');
    }
}